import { createRouter, createWebHistory } from 'vue-router'
import { ROOT_ROUTE_NAME } from '../utils/consts'
import { routes } from './routes'
import Frame from '../components/frame/Index.vue'
import { navInterceptor } from '../utils/modal'

export * from './routes'

export const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: ROOT_ROUTE_NAME,
      component: Frame,
      children: [
        {
          path: '',
          name: 'home',
          meta: { title: '首页' },
          component: () => import('../pages/home/Index.vue')
        },
        ...routes
      ]
    },
    {
      path: '/api_create/:id?',
      component:  () => import('../pages/apis/Create.vue'),
    },
    {
      path: '/test/:id?',
      component:  () => import('../pages/apis/Create.vue'),
    }
  ]
})

router.beforeEach((to, _, next) => navInterceptor(to, next))
